//
//  ZhuangHuoViewController.m
//  Rabbit
//
//  Created 阿帕 on 2019/12/19.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "QRZhuangHuoViewController.h"
#import "TZImagePickerController.h"
#import "DriverVehicleModel.h"
#import "PersonCenterModel.h"
#import "ZXCollectionCell.h"

#ifdef isOpenBaiDuFaceSDK
//人脸识别
#import "BDFaceLivenessViewController.h"
#import "BDFaceDetectionViewController.h"
#import "BDFaceLivingConfigModel.h"
#import "IDLFaceSDK/IDLFaceSDK.h"
#import "FaceParameterConfig.h"
#endif

#define UploadImgOne 220320
#define UploadImgTwo 220321

#define DefaultLocationTimeout 10
#define DefaultReGeocodeTimeout 5

@interface QRZhuangHuoViewController ()<AMapLocationManagerDelegate, TZImagePickerControllerDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
    NSString *_zhuangCheDate;
    NSString *_longitude;
    NSString *_latitude;
    UIImage  *_renCheHuoImage;
    UIImage  *_danJuImage;
    NSString *_renCheHuoUrl;
    NSString *_danJuUrl;
    NSString *_locateAddress;
    UIImagePickerController *_ipc;//图片选择器
}
@property (nonatomic, strong) AMapLocationManager *locationManager;
@property (nonatomic,strong) NSMutableArray *imageArr;
@property (nonatomic,strong) NSMutableArray *imageUrlArray;
@property (nonatomic,strong) UICollectionView *collectionView;

@property (nonatomic, strong) NSString *orderType;
//@property (nonatomic, strong) NSString *vehicleCode;
@property (nonatomic, strong) NSString *teamCode;
@property (nonatomic, strong) NSMutableArray *teamTitleArr;
@property (nonatomic, strong) NSMutableArray *teamArr;
@property (nonatomic, strong) NSMutableArray *vehicleTitleArr;
@property (nonatomic, strong) NSArray *vehicleArr;

@property (weak, nonatomic) IBOutlet UILabel *dunShuText;
@property (weak, nonatomic) IBOutlet UILabel *shuLiangText;
@property (weak, nonatomic) IBOutlet UILabel *dateText;

@property (weak, nonatomic) IBOutlet UITextField *typeTextField;
@property (weak, nonatomic) IBOutlet UITextField *teamTextField;
@property (weak, nonatomic) IBOutlet UITextField *vehicleTextField;
@property (weak, nonatomic) IBOutlet UITextField *dunShuTextField;
@property (weak, nonatomic) IBOutlet UITextField *shuLiangTextField;
@property (weak, nonatomic) IBOutlet UITextField *dateTextField;

@property (weak, nonatomic) IBOutlet UIView *typeView;
@property (weak, nonatomic) IBOutlet UIView *teamView;
@property (weak, nonatomic) IBOutlet UIView *vehicleView;
@property (weak, nonatomic) IBOutlet UIView *dunShuView;
@property (weak, nonatomic) IBOutlet UIView *shuLiangView;
@property (weak, nonatomic) IBOutlet UIView *dateView;
@property (weak, nonatomic) IBOutlet UIButton *typeBtn;

@property (weak, nonatomic) IBOutlet UIButton *saveButton;
@property (weak, nonatomic) IBOutlet UILabel *tipTextLabel;
@property (weak, nonatomic) IBOutlet UIView *photoBgView;

@end

@implementation QRZhuangHuoViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [KNotificationCenter addObserver:self selector:@selector(faceIdentifyCompleted:) name:@"faceIdentifySuccess" object:nil];

    self.view.backgroundColor = [UIColor whiteColor];
    
    [self configLocationManager];
    
    [self baseSetUp];
    
    WEAKSELF
    [KSPTHandler locationPermissionCheck:^(bool permit) {
        if (!permit) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
    }];
    
    // 2k人车分离
    _orderType = @"";
    _teamCode = @"";
    _vehicleCode = @"";
    if (_status == 0) {
        [self getVehicleData];
        
        if ([_ydModel.teamName isNotBlank]) {
            self.orderType = @"2";
            self.typeTextField.text = @"车队运单";
            [self getTeamData];
            
        } else {
            self.orderType = @"1";
            self.typeTextField.text = @"个人运单";
            
            self.typeBtn.enabled = NO;
            self.teamView.hidden = YES;
        }
    }
    
    if (_status == 1 || CarCaptain_Driver) {
        _typeView.hidden = YES;
        _teamView.hidden = YES;
        _vehicleView.hidden = YES;
    }
}


- (void)baseSetUp {
    
    _ipc = [[UIImagePickerController alloc] init];
    _ipc.delegate = self;
    _ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
    _ipc.showsCameraControls = YES;
    
    _zhuangCheDate = @"";
    _longitude = @"";
    _latitude = @"";
    _renCheHuoUrl = @"";
    _danJuUrl = @"";
    _locateAddress= @"";
    
    _dunShuTextField.textFieldType = CJTextFieldStringTypeThreeDecimalPlaces;
    _dunShuTextField.maxLength = 20;
    
    _shuLiangTextField.textFieldType = CJTextFieldStringTypeThreeDecimalPlaces;
    _shuLiangTextField.maxLength = 20;
    
    [_dateView setHidden:YES];
    
    cut(_saveButton, BTN_BORDER_RADIUS);
    [_saveButton setBackgroundColor:Theme_ColorValue];
    
    if (_status == 0) {
        //装货 卸货吨位（吨）、卸货数量（方）
        self.navigationItem.title = @"装货";
        _dunShuText.text = @"装货吨位（吨）";
        _dateText.text = @"装车时间";
        _dateTextField.placeholder = @"请选择装车时间";
        [_saveButton setTitle:@"装货" forState:UIControlStateNormal];
    } else {
        //卸货
        self.navigationItem.title = @"卸货";
        _dunShuText.text = @"卸货吨位（吨）";
        _dateText.text = @"卸车时间";
        _dateTextField.placeholder = @"请选择卸车时间";
        [_saveButton setTitle:@"卸货" forState:UIControlStateNormal];
    }
    
    //装货-装货数量增加货源单位-若货源单位为吨则只显示装车吨位-若为方或件则进行输入吨位与单位数量
    if ([_coalUnit isEqual:@"0"]) {
        if (_status == 0) {
            _shuLiangText.text = CJStringWithFormat(@"装货数量（吨）");
        } else {
            _shuLiangText.text = CJStringWithFormat(@"卸货数量（吨）");
        }
        [_shuLiangView setHidden:YES];
        
    } else if ([_coalUnit isEqual:@"1"]) {
        
        if (_status == 0) {
            _shuLiangText.text = CJStringWithFormat(@"装货数量（方）");
        } else {
            _shuLiangText.text = CJStringWithFormat(@"卸货数量（方）");
        }
    } else if ([_coalUnit isEqual:@"2"]) {
        
        if (_status == 0) {
            _shuLiangText.text = CJStringWithFormat(@"装货数量（件）");
        } else {
            _shuLiangText.text = CJStringWithFormat(@"卸货数量（件）");
        }
        
        _shuLiangTextField.textFieldType = CJTextFieldStringTypeNumber;
        _shuLiangTextField.keyboardType = UIKeyboardTypeNumberPad;
        _shuLiangTextField.maxLength = 10;
    }
    
    //使用按钮布局
    [self gridViewLayout];
    
}

- (void)gridViewLayout {
    if (_photoBgView) {
        [_photoBgView removeAllSubviews];
    }
    
    CGFloat width = (ScreenW-50)/4;
    
    NSArray *btnTitles = @[_status==0?@"人车货合照":@"磅单", _status==0?@"装货交接单":@"过路费发票", @"添加图片"];
    
    for (int i=0; i<self.imageArr.count; i++) {
        
        int x = i%4;
        int y = i/4;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 200 + i;
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitleColor:[UIColor cy_colorWithHexString:@"#B5CBE2"] forState:UIControlStateNormal];
        button.titleLabel.font = font(12);
        button.titleLabel.adjustsFontSizeToFitWidth = YES;
        button.frame = CGRectMake(x*width+10*(x+1), 10 + y*width + 15*y, width, width);
        [DCSpeedy cy_setControlDottedLineBorder:button SetBorderWidth:1 SetBorderColor:[UIColor cy_colorWithHexString:@"#B5CBE2"]];
        [button addTarget:self action:@selector(photoButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_photoBgView addSubview:button];
        
        //删除按钮
        UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleteBtn.tag = 300 + i;
        deleteBtn.hidden = YES;
        deleteBtn.frame = CGRectMake(button.width - 20, 0, 20, 20);
        [deleteBtn setImage:image(@"gcy_icon_img_delete") forState:UIControlStateNormal];
        [deleteBtn addTarget:self action:@selector(deletePhotoClick:) forControlEvents:UIControlEventTouchUpInside];
        [button addSubview:deleteBtn];

        if (i<3) {
            [button setTitle:btnTitles[i] forState:UIControlStateNormal];
            if (i==0) {
                deleteBtn.tag = UploadImgOne;
                
                if (_renCheHuoImage) {
                    deleteBtn.hidden = NO;
                    [button setBackgroundImage:_renCheHuoImage forState:UIControlStateNormal];
                } else {
                    [button setImage:self.imageArr[i] forState:UIControlStateNormal];
                }
                
            } else if (i==1) {
                deleteBtn.tag = UploadImgTwo;
                
                if (_danJuImage) {
                    deleteBtn.hidden = NO;
                    [button setBackgroundImage:_danJuImage forState:UIControlStateNormal];
                } else {
                    [button setImage:self.imageArr[i] forState:UIControlStateNormal];
                }
                
            } else {
                [button setImage:self.imageArr[i] forState:UIControlStateNormal];
            }
            
        } else {
            [button setBackgroundImage:self.imageArr[i] forState:UIControlStateNormal];
            deleteBtn.hidden = NO;
        }
        
        [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:20];
        
       
    }
    
}

- (void)photoButtonClick:(UIButton *)button {
    
    NSUInteger tag = button.tag;
    if (tag <= 202) {
        //选择
        if (self.imageArr.count == 10) {
            [XSInfoView showInfo:@"最多可上传9张图片" onView:self.view];
        } else {
            
            if (tag == 200 && [_renCheHuoUrl isNotBlank]) {
                // 查看
                HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
                browser.isFullWidthForLandScape = YES;
                browser.isNeedLandscape = YES;
                browser.currentImageIndex = 0;
                browser.imageArray = @[_renCheHuoUrl];
                [browser show];
                
            } else if (tag == 201 && [_danJuUrl isNotBlank]) {
                // 查看
                HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
                browser.isFullWidthForLandScape = YES;
                browser.isNeedLandscape = YES;
                browser.currentImageIndex = 0;
                browser.imageArray = @[_danJuUrl];
                [browser show];
                
            } else {
                
                [SystemPermissionsToolObject determineLatestPermissionsOfTheLocalAlbum];
                
                TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:nil pushPhotoPickerVc:YES];
                imagePickerVc.allowPickingVideo = NO;
                [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
                    
                    if (tag == 200) {
                        
                        UIButton *rchBtn = [self.view viewWithTag:200];
                        [rchBtn setImage:nil forState:UIControlStateNormal];
                        [rchBtn setTitle:@"" forState:UIControlStateNormal];
                        
                    } else if (tag == 201) {
                        
                        UIButton *djBtn = [self.view viewWithTag:201];
                        [djBtn setImage:nil forState:UIControlStateNormal];
                        [djBtn setTitle:@"" forState:UIControlStateNormal];
                        
                    } else {
                        
                        UIButton *delBtn = [self.view viewWithTag:button.tag+101];
                        delBtn.hidden = NO;
                        [self.imageArr addObjectsFromArray:photos];
                    }
                    
                    UIImage *watermarkImage = [DCSpeedy addWatermarkToPicture:[photos firstObject] :[DCSpeedy currentDate] :_locateAddress :CJStringWithFormat(@"经度:%@，纬度:%@", _longitude, _latitude)];
                    
                    [HTTPManager postUploadFiles:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], FILE_UPLOAD) file:@[watermarkImage] fileName:@"file" withVC:self netName:@"文件上传" success:^(id response, NSString *msg) {
                        
                        if (button.tag == 200) {
                            
                            _renCheHuoUrl = response[@"data"];
                            
                            _renCheHuoImage = watermarkImage;
                            
                        } else if (button.tag == 201) {
                            
                            _danJuUrl = response[@"data"];
                            
                            _danJuImage = watermarkImage;
                            
                        } else {
                            [self.imageUrlArray addObject:response[@"data"]];
                        }
                        
                        [self gridViewLayout];
                        
                    } failure:^(NSInteger code, NSString *msg) {
                        
                    }];
                    
                }];
                imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
                [self presentViewController:imagePickerVc animated:YES completion:nil];
                
            }
            
        }
        
    } else {
        
        DebugLog(@"%ld", button.tag);
        DebugLog(@"%@", self.imageUrlArray);

        //查看
        HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
        browser.isFullWidthForLandScape = YES;
        browser.isNeedLandscape = YES;
        browser.currentImageIndex = (int)(button.tag - 203);
        browser.imageArray = self.imageUrlArray;
        [browser show];
        
    }
}

/// 获取图片格式
- (NSString *)typeForImageData:(NSData *)data {
    uint8_t c;
    [data getBytes:&c length:1];
    switch (c) {
        case 0xFF:
            return @"image/jpeg";
            
        case 0x89:
            return @"image/png";
            
        case 0x47:
            return @"image/gif";
            
        case 0x49:
            
        case 0x4D:
            return @"image/tiff";
    }
    
    return nil;
}


#pragma mark - 活体检测结果通知
- (void)faceIdentifyCompleted:(NSNotification *)notifi {
    
    NSDictionary *parmas = @{
        @"imageUrl": notifi.object,
//        @"identificationImg": _identificationImg, 不传身份证这个字段
        @"livenessVerify": @"1",
        @"branchCode": _branchCode,
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
    };
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_VERIFYIDENTITY) withParameter:parmas withVC:self netName:@"身份验证" success:^(id response, NSString *msg) {
                
        if ([response[@"pass"] integerValue] == 1) {
            
            [self zhuangXieRequest];
            
        } else {
            
            [XSInfoView showInfo:response[@"msg"] onView:self.view];
            
        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (void)deletePhotoClick:(UIButton *)button {
    
    if (button.tag == UploadImgOne) {
        _renCheHuoUrl = @"";
        _renCheHuoImage = nil;
    } else if (button.tag == UploadImgTwo) {
        _danJuUrl = @"";
        _danJuImage = nil;
    }
    
    if ((_renCheHuoImage && _danJuImage == nil) || (_danJuImage && _renCheHuoImage == nil)) {
        [self.imageArr removeObjectAtIndex:button.tag - 300];
        [self.imageUrlArray removeObjectAtIndex:button.tag - 303];
    } else if (_renCheHuoImage && _danJuImage) {
        [self.imageArr removeObjectAtIndex:button.tag - 300];
        [self.imageUrlArray removeObjectAtIndex:button.tag - 303];
    } else {
        [self.imageArr removeObjectAtIndex:button.tag - 300];
        [self.imageUrlArray removeObjectAtIndex:button.tag - 303];
    }
    
    [self gridViewLayout];

}

- (void)getTeamData {
    NSDictionary *params = @{
        @"pageSize": @9999,
        @"pageNum": @1,
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
    };
    
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_JOINEDTEAMLIST) withParameter:params withVC:self netName:@"已加入车队列表" success:^(id response, NSString *msg) {
        
        if ([response[@"records"] count] > 0) {
            self.teamArr = [NSMutableArray array];
             self.teamTitleArr = [NSMutableArray array];
            
            [self.teamArr addObjectsFromArray:[CarTeamModel mj_objectArrayWithKeyValuesArray:response[@"records"]]];
            
            for (int i = 0; i < self.teamArr.count; i++) {
                CarTeamModel *model = self.teamArr[i];
                [self.teamTitleArr addObject:model.name];
                
                if (i == 0) {
                    self.teamCode = model.code;
                    self.teamTextField.text = model.name;
                }
            }
            
        } else {
            self.orderType = @"1";
            self.typeTextField.text = @"个人运单";
            self.typeView.hidden = YES;
            self.teamView.hidden = YES;
        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (void)getVehicleData {
    NSDictionary *pamars = @{
        @"authStatusExt": @3,
        @"pageSize": @"9999",
        @"pageNum": @1,
    };
    
    NSString *listUrl = CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], @"/vehicle/bindList");
    
    @weakify(self);
    [HTTPManager jsonNetworkRequestWithMethod:@"GET"
                                    urlString:listUrl
                                withParameter:pamars
                                       withVC:self
                                      netName:@"车辆列表"
                                      success:^(id response, NSString *msg) {
        @strongify(self);
        NSArray *vehicleArr = [DriverVehicleModel mj_objectArrayWithKeyValuesArray:response[@"records"]];
        if (vehicleArr.count == 0) {
            return;
        }
        NSMutableArray *arr = [NSMutableArray array];
        for (DriverVehicleModel *model in vehicleArr) {
            [arr addObject:model.licenseNumber];
            
            if ([model.vehicleCode isNotBlank]) {
                self.vehicleCode = model.code;
                self.vehicleTextField.text = model.licenseNumber;
            }
        }
        
//        DriverVehicleModel *vehicle = [vehicleArr firstObject];
//        self.vehicleCode = vehicle.code;
//        self.vehicleTextField.text = vehicle.licenseNumber;
        
        self.vehicleArr = vehicleArr;
        self.vehicleTitleArr = arr;
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (IBAction)typeBtnOnclicked:(UIButton *)sender {
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] initWithPickerMode:BRStringPickerComponentSingle];
    stringPickerView.title = @"请选择订单类型";
    stringPickerView.dataSourceArr = @[@"个人运单", @"车队运单"];
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        
        self.typeTextField.text = resultModel.selectValue;
        self.orderType = [NSString stringWithFormat:@"%ld", resultModel.index + 1];
        
        self.teamView.hidden = [resultModel.selectValue containsString:@"个人"];
    };
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:[UIColor cjMainColor]];
    customStyle.topCornerRadius = 7;
    stringPickerView.pickerStyle = customStyle;
    [stringPickerView show];
}

- (IBAction)teamBtnOnclicked:(UIButton *)sender {
    if (self.teamArr.count == 0) {
        [XSInfoView showInfo:@"没有查询到审核通过的车队信息" onView:self.view];
        return;
    }
    
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] initWithPickerMode:BRStringPickerComponentSingle];
    stringPickerView.title = @"选择所属车队";
    stringPickerView.dataSourceArr = self.teamTitleArr;
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        CarTeamModel *model = self.teamArr[resultModel.index];
        self.teamCode = model.teamCode;
        self.teamTextField.text = model.name;
    };
    
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:Theme_ColorValue];
    customStyle.topCornerRadius = 7;
    stringPickerView.pickerStyle = customStyle;
    [stringPickerView show];
}

- (IBAction)vehicleBtnOnclicked:(UIButton *)sender {
    if (self.vehicleArr.count == 0) {
        [XSInfoView showInfo:@"没有查询到审核通过的车辆信息" onView:self.view];
        return;
    }
    
    BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] initWithPickerMode:BRStringPickerComponentSingle];
    stringPickerView.title = @"选择承运车辆";
    stringPickerView.dataSourceArr = self.vehicleTitleArr;
    stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        DriverVehicleModel *vehicle = self.vehicleArr[resultModel.index];
        NSString *vehicleCode = vehicle.code;
        self.vehicleCode = vehicleCode;
        self.vehicleTextField.text = vehicle.licenseNumber;
    };
    
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:Theme_ColorValue];
    customStyle.topCornerRadius = 7;
    stringPickerView.pickerStyle = customStyle;
    [stringPickerView show];
}

- (IBAction)buttonTypeClick:(UIButton *)sender {
    
    if (sender.tag == 10) {
        
        // 1.创建日期选择器
        BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMDHMS];
        // 2.设置属性
        datePickerView.title = @"选择日期";
        datePickerView.isAutoSelect = NO;
        datePickerView.showToday = NO; // 是否显示“今天”
        datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
            NSLog(@"选择的值：%@", selectValue);
            
            [sender setTitle:selectValue forState:UIControlStateNormal];
            _zhuangCheDate = selectValue;
        };
        // 3.显示
        [datePickerView show:self];
        
    } else if (sender.tag == 20) {
        //装卸货确认按钮
        DebugLog(@"imageUrlArray = %@", self.imageUrlArray);
        
        if ([self locationIsAlwaysAuth] == NO) {
            return;
        }
        
        if ([_coalUnit isEqual:@"0"]) {
            
            if ([DCSpeedy isBlankString:_dunShuTextField.text]) {
                [XSInfoView showInfo:@"必填信息不能为空" onView:self.view];
                return;
            }
//            if ([DCSpeedy isBlankArr:self.imageUrlArray] == YES) {
//                [XSInfoView showInfo:@"请上传图片" onView:self.view];
//                return;
//            }
            
        } else {
            
            if ([DCSpeedy isBlankString:_dunShuTextField.text] || [DCSpeedy isBlankString:_shuLiangTextField.text]) {
                [XSInfoView showInfo:@"必填信息不能为空" onView:self.view];
                return;
            }
//            if ([DCSpeedy isBlankArr:self.imageUrlArray] == YES) {
//                [XSInfoView showInfo:@"请上传图片" onView:self.view];
//                return;
//            }
        }
        
//        if ([DCSpeedy isBlankString:_renCheHuoUrl] == YES) {
//            [XSInfoView showInfo:@"请上传磅单" onView:self.view];
//            return;
//        }
//        if ([DCSpeedy isBlankString:_danJuUrl] == YES) {
//            if (_status == 0) {
//                [XSInfoView showInfo:@"请上传装货交接单" onView:self.view];
//            } else {
//                [XSInfoView showInfo:@"请上传卸货签收单" onView:self.view];
//            }
//            return;
//        }
      
        if (_status == 0) {
    
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            [params setValue:_ydModel.branchCode forKey:@"branchCode"];
            [params setValue:[UserDefaultUtil valueForKey:USER_TOKEN] forKey:@"token"];
            [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_VERIFYIDENTITYONOFF) withParameter:params withVC:self netName:@"是否开启身份验证" success:^(id response, NSString *msg) {
                
                //toVerifyIdentity 0 未开启 1 活体检测 2 拍照检测
                if ([response[@"toVerifyIdentity"] integerValue] == 2) {
                    
                    [DCSpeedy dc_SetUpSingleAlterWithView:self Title:@"⚠️重要提示⚠️" Message:@"装货时需要人证核验，请拍摄本人照片" tureTitle:@"点击继续" Sure:^{
                        
                        [self presentViewController:_ipc animated:YES completion:nil];
                    }];
                    
                } else if ([response[@"toVerifyIdentity"] integerValue] == 1) {
                    
                    //使用活体检测方式人证核验
                    //开启了
#ifdef isOpenBaiDuFaceSDK
                    if (![[FaceSDKManager sharedInstance] canWork]) {
                        [XSInfoView showInfo:@"该项目未配置活体检测,请联系管理员" onView:self.view];
                    } else {
                        [self faceLiveness];
                    }
#else
                    [XSInfoView showInfo:@"未配置活体检测，请联系管理员关闭核验或开启活体检测功能!" onView:self.view];
#endif
                } else {
                    
                    //两种方式都未开启
                    [self zhuangXieRequest];
                }
                
            } failure:^(NSInteger code, NSString *msg) {
                
            }];
            
        } else {
            //卸货
            [self zhuangXieRequest];
        }
        
    }
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
    //判断媒体资源类型，（图片或者是视频）
    NSString *imageType = [info objectForKey:UIImagePickerControllerMediaType];
    UIImage *gerenimage = [[UIImage alloc] init];
    //如果是图片资源
    if ([imageType isEqualToString:(NSString *)kUTTypeImage]) {
        //取到从系统图片库选择的图片或者照相机拍摄的图片
        if (_ipc.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
            gerenimage = [info objectForKey:UIImagePickerControllerOriginalImage];
        }else if(_ipc.sourceType == UIImagePickerControllerSourceTypeCamera){
            gerenimage = [info objectForKey:UIImagePickerControllerOriginalImage];
        }
        UIImageOrientation imageOrientation = gerenimage.imageOrientation;
        if(imageOrientation!=UIImageOrientationUp)
        {
            // 原始图片可以根据照相时的角度来显示，但UIImage无法判定，于是出现获取的图片会向左转９０度的现象。
            // 以下为调整图片角度的部分
            UIGraphicsBeginImageContext(gerenimage.size);
            [gerenimage drawInRect:CGRectMake(0, 0, gerenimage.size.width, gerenimage.size.height)];
            gerenimage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            // 调整图片角度完毕
        }
        
    }
    
    NSMutableArray *muArr = [[NSMutableArray alloc] init];
    [muArr addObject:gerenimage];
    
    //发送头像请求
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [HTTPManager postUploadFiles:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], FILE_UPLOAD) file:muArr fileName:@"file" withVC:self netName:@"文件上传" success:^(id response, NSString *msg) {
            
            NSDictionary *parmas = @{
                @"peopleImg": response[@"data"],
                @"branchCode": [UserDefaultUtil valueForKey:BranchCode],
                @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
            };
            //                            图片的用这个/driver/verifyIdentityImg
            [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@/ntocc-basic-api/driver/verifyIdentityImg", BasicDomainURL) withParameter:parmas withVC:self netName:@"身份验证" success:^(id response, NSString *msg) {
                
                if ([response[@"pass"] integerValue] == 1) {
                    
                    [self zhuangXieRequest];
                    
                } else {
                    
                    [XSInfoView showInfo:response[@"msg"] onView:self.view];
                }
                
            } failure:^(NSInteger code, NSString *msg) {
                
            }];
            
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
        
    });
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    //更改picker的导航条颜色 及item的tintcolor
    if ([_ipc.navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
        _ipc.navigationBar.tintColor = [UIColor cy_colorWithHexString:@"484848"];
        _ipc.navigationBar.translucent = NO;
        _ipc.navigationBar.barTintColor = [UIColor whiteColor];
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        
        //设置导航标题的属性
        [_ipc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor cy_colorWithHexString:@"484848"], NSFontAttributeName: [UIFont systemFontOfSize:18]}];
        //        _ipc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;//弹出模式
        _ipc.allowsEditing = YES;
    }
    
}

#ifdef isOpenBaiDuFaceSDK
//人脸认证
- (void)faceLiveness {
    BDFaceLivenessViewController* lvc = [[BDFaceLivenessViewController alloc] init];
    BDFaceLivingConfigModel* model = [BDFaceLivingConfigModel sharedInstance];
    [lvc livenesswithList:model.liveActionArray order:model.isByOrder numberOfLiveness:model.numOfLiveness];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:lvc];
    navi.navigationBarHidden = true;
    navi.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:navi animated:YES completion:nil];
}
#endif

#pragma mark - 装卸货请求
- (void)loadingSave:(NSString *)resultStr completed:(void(^)(bool success, NSDictionary *obj))completed {
    WEAKSELF
    NSDictionary *params = @{
        @"mainOrderCode": _orderCode,
        @"code": _code,
        @"imgUrl": resultStr,
        @"weight": _dunShuTextField.text,
        @"quantity": _shuLiangTextField.text,
        @"orderType": weakSelf.orderType,
        @"teamCode": weakSelf.teamCode,
        @"vehicleCode": weakSelf.vehicleCode,
        //        @"time" : _zhuangCheDate,
        @"time" : [DCSpeedy getCurrentTimes],
        @"longitude": _longitude,
        @"latitude": _latitude,
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
    };
    
    // 装货保存
    [HTTPManager putNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tms-api",[ReAddressDynamic shared].baseUrl], ORDERDETAIL_TAKEORDERANDLOAD) withParameter:params withVC:self netName:@"扫码接单装货" success:^(id response, NSString *msg) {
        
        [XSInfoView showInfo:msg onView:self.view];
        
        [KNotificationCenter postNotificationName:YUNDANCENTERLIST_REFRESH object:nil];
        
        if (completed) {
            if ([response[@"status"] intValue] == 0) {
                completed(true, [response objectForKey:@"data"]);
            } else {
                completed(false, @{});
            }
            
        } else {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            });
        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
        if (code == 3001) {
            //未签约授权
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"操作提醒" message:msg preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *goAction = [UIAlertAction actionWithTitle:@"去授权" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                NSDictionary *parmas = @{
                    @"sysType": @"app",
                    @"appType": @"driver",
                    @"branchCode": [UserDefaultUtil valueForKey:BranchCode],
                    @"page": @"main",
                    @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
                };
                
                [HTTPManager postNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tms-api",[ReAddressDynamic shared].baseUrl], MERCHPREAPPLY) withParameter:parmas withVC:self netName:@"签约授权" success:^(id response, NSString *msg) {
                    
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:response] options:@{} completionHandler:nil];
                    
                } failure:^(NSInteger code, NSString *msg) {
                    
                }];
            }];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            }];
            
            [alertController addAction:goAction];
            [alertController addAction:cancelAction];
            [self presentViewController:alertController animated:YES completion:nil];
        }
        
        if (completed) {
            completed(false, nil);
        }
    }];
}

static void unloadSave(QRZhuangHuoViewController *object, NSString *resultStr, QRZhuangHuoViewController *const __weak weakSelf) {
    NSDictionary *params = @{
        @"mainOrderCode": object->_orderCode,
        @"code": object->_code,
        @"imgUrl": resultStr,
        @"weight": object->_dunShuTextField.text,
        @"quantity": object->_shuLiangTextField.text,
        //        @"time" : _zhuangCheDate,
        @"time" : [DCSpeedy getCurrentTimes],
        @"longitude": object->_longitude,
        @"latitude": object->_latitude,
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
    };
    [HTTPManager putNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tms-api",[ReAddressDynamic shared].baseUrl], ORDER_DETAIL_UPLOADTICKETIMAGE) withParameter:params withVC:weakSelf netName:@"卸货保存" success:^(id response, NSString *msg) {
        
        [XSInfoView showInfo:msg onView:weakSelf.view];
        
        [KNotificationCenter postNotificationName:YUNDANCENTERLIST_REFRESH object:nil];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
            [weakSelf.navigationController popViewControllerAnimated:YES];
        });
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (void)zhuangXieRequest {
    
    WEAKSELF
    /*
     第一张为空imgurl:,url,url
     第二张为空imgurl:url,,url
     前两张都为空imgurl:,,url
     */
    NSString *arrStr;
    NSString *resultStr;
    
    if ([DCSpeedy isBlankArr:self.imageUrlArray]) {
        arrStr = @"";
    } else {
        arrStr = [self.imageUrlArray componentsJoinedByString:@","];
    }
    
    if ([DCSpeedy isBlankString:_danJuUrl] && [DCSpeedy isBlankString:_renCheHuoUrl] && [DCSpeedy isBlankArr:self.imageUrlArray]) {
        //全部为空
        resultStr = @"";
    } else if ([DCSpeedy isBlankString:_renCheHuoUrl] && [DCSpeedy isBlankString:_danJuUrl] == NO) {
        //第一张为空，第二张不为空
        resultStr = [NSString stringWithFormat:@",%@%@", _danJuUrl, arrStr];
    } else if ([DCSpeedy isBlankString:_danJuUrl] && [DCSpeedy isBlankString:_renCheHuoUrl] == NO) {
        //第一张不为空，第二张为空
        resultStr = [NSString stringWithFormat:@"%@,,%@", _renCheHuoUrl, arrStr];
    } else if ([DCSpeedy isBlankString:_danJuUrl] == NO && [DCSpeedy isBlankString:_renCheHuoUrl] == NO && [DCSpeedy isBlankArr:self.imageUrlArray]) {
        
        resultStr = [NSString stringWithFormat:@"%@,%@,", _renCheHuoUrl, _danJuUrl];
        
    } else if ([DCSpeedy isBlankString:_danJuUrl] == NO && [DCSpeedy isBlankString:_renCheHuoUrl] == NO && [DCSpeedy isBlankArr:self.imageUrlArray] == NO) {
        
        resultStr = [NSString stringWithFormat:@"%@,%@,%@", _renCheHuoUrl, _danJuUrl, arrStr];
        
    } else if ([DCSpeedy isBlankString:_danJuUrl] && [DCSpeedy isBlankString:_renCheHuoUrl] && [DCSpeedy isBlankArr:self.imageUrlArray] == NO) {
        //第一张为空，第二张为空
        resultStr = [NSString stringWithFormat:@",,%@", arrStr];
    }  else {
        resultStr = @"";
    }
    
    NSMutableDictionary *shippingNoteInfo = [NSMutableDictionary dictionary];
    [shippingNoteInfo setValue:@"0000" forKey:@"serialNumber"];
    [shippingNoteInfo setValue:_shippingNoteNumber forKey:@"shippingNoteNumber"];
    [shippingNoteInfo setValue:_startCountrySubdivisionCode forKey:@"startCountrySubdivisionCode"];
    [shippingNoteInfo setValue:_endCountrySubdivisionCode forKey:@"endCountrySubdivisionCode"];
    [shippingNoteInfo setValue:_ydModel.loadLongitude forKey:@"startLongitude"];
    [shippingNoteInfo setValue:_ydModel.loadLatitude forKey:@"startLatitude"];
    [shippingNoteInfo setValue:_ydModel.consigneeLongitude forKey:@"endLongitude"];
    [shippingNoteInfo setValue:_ydModel.consigneeLatitude forKey:@"endLatitude"];
    
    NSString *endLocationText = [_ydModel.consigneeAddress stringByAppendingString:_ydModel.consigneeDetailAddress];
    NSString *startLocationText = [[NSString alloc]initWithFormat:@"%@%@",_ydModel.shipperAddress,_ydModel.shipperDetailAddress];
    [shippingNoteInfo setValue:startLocationText forKey:@"startLocationText"];
    [shippingNoteInfo setValue:endLocationText forKey:@"endLocationText"];
    
    if (_status == 0) { // 装货
        
        [[KSPTHandler shippingNoteInfos] addObject:[shippingNoteInfo deepCopy]];
        [KSPTHandler configSPTHandlerWithBranchCode:_ydModel.branchCode completed:^(bool isSuccess, NSInteger code, NSString *msg) {
            
            if (isSuccess) {
                [weakSelf loadingSave:resultStr completed:^(bool success, NSDictionary *obj) {
                    if (success) {
                        [shippingNoteInfo setValue:KSPTHandler.address forKey:@"startLocationText"];
                        [shippingNoteInfo setValue:CJStringWithFormat(@"%.6f", KSPTHandler.location.coordinate.longitude) forKey:@"startLongitude"];
                        [shippingNoteInfo setValue:CJStringWithFormat(@"%.6f", KSPTHandler.location.coordinate.latitude) forKey:@"startLatitude"];
                        
                        [shippingNoteInfo setValue:obj[@"shippingNoteNumber"] forKey:@"shippingNoteNumber"];
                        [shippingNoteInfo setValue:obj[@"shipperSubdivisionCode"] forKey:@"startCountrySubdivisionCode"];
                        [shippingNoteInfo setValue:obj[@"consigneeSubdivisionCode"] forKey:@"endCountrySubdivisionCode"];
                        
                        [KSPTHandler startLocationWithShippingNoteInfos:@[shippingNoteInfo] remark:@"开始装货" branchCode:nil isRecord:NO listener:^(id model) {
                            if ([model[@"code"] intValue] == 0) {
                                // 开始上报完成->装货保存
                                [KSPTHandler orderReportRecord:model stage:SPTStageStart stageStr:@"start" dataArray:@[shippingNoteInfo] completed:^(bool isSuccess) {
                                    
                                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
                                        [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                                    });
                                }];
                            } else {
                                [XSInfoView showInfo:model[@"message"] onView:weakSelf.view];
                            }
                        }];
                    }
                }];
                
            } else { // 失败
                
                if (!isSuccess && code == -1) {
                    // 未启用上报-装货保存
                    [weakSelf loadingSave:resultStr completed:nil];
                    return;
                    
                } else {
                    [XSInfoView showInfo:msg onView:weakSelf.view];
                }
            }
        }];
        
    } else { // 卸货
        
        [KSPTHandler configSPTHandlerWithBranchCode:_ydModel.branchCode completed:^(bool isSuccess, NSInteger code, NSString *msg) {
            
            if (isSuccess) {
                [shippingNoteInfo setValue:KSPTHandler.address forKey:@"endLocationText"];
                [shippingNoteInfo setValue:CJStringWithFormat(@"%.6f", KSPTHandler.location.coordinate.longitude) forKey:@"endLongitude"];
                [shippingNoteInfo setValue:CJStringWithFormat(@"%.6f", KSPTHandler.location.coordinate.latitude) forKey:@"endLatitude"];
                
                [KSPTHandler stopLocationWithShippingNoteInfos:@[shippingNoteInfo] remark:@"结束卸货" branchCode:nil isRecord:NO listener:^(id model) {
                    int code = [model[@"code"] intValue];
                    if (code == 0) {
                        // 结束上报完成->卸货保存
                        [KSPTHandler orderReportRecord:model stage:SPTStageStop stageStr:@"stop" dataArray:@[shippingNoteInfo] completed:^(bool isSuccess) {
                            unloadSave(self, resultStr, weakSelf);
                        }];
                    } else if (code == 888884 || code == 100044) {
                        // 卸货失败-重试
                        [KSPTHandler reStartLocationWithShippingNoteInfos:@[shippingNoteInfo] remark:@"[02]卸货失败重试" branchCode:nil isRecord:YES listener:^(id model) {
                            if ([model[@"code"] intValue] == 0) {
                                
                                [KSPTHandler stopLocationWithShippingNoteInfos:@[shippingNoteInfo] remark:@"'结束卸货'" branchCode:nil isRecord:NO listener:^(id model) {
                                    
                                    int reCode = [model[@"code"] intValue];
                                    if (reCode == 0) { // 重试后正常
                                        [KSPTHandler orderReportRecord:model stage:SPTStageStop stageStr:@"stop" dataArray:@[shippingNoteInfo] completed:^(bool isSuccess) {
                                            unloadSave(self, resultStr, weakSelf);
                                        }];
                                        
                                    } else if (reCode == 888884 || reCode == 100044) { // 再次报错直接卸货
                                        [KSPTHandler orderReportRecord:model stage:SPTStageStop stageStr:@"stop" dataArray:@[shippingNoteInfo] completed:^(bool isSuccess) {
                                            unloadSave(self, resultStr, weakSelf);
                                        }];
                                        
                                    } else {
                                        [XSInfoView showInfo:model[@"message"] onView:weakSelf.view];
                                    }
                                }];
                                
                            } else {
                                unloadSave(self, resultStr, weakSelf);
                            }
                        }];
                        
                    } else {
                        [XSInfoView showInfo:model[@"message"] onView:weakSelf.view];
                    }
                }];
                
            } else { // 失败
                
                if (!isSuccess && code == -1) {
                    // 未启用上报-卸货货保存
                    unloadSave(self, resultStr, weakSelf);
                    return;
                    
                } else {
                    [XSInfoView showInfo:msg onView:weakSelf.view];
                }
            }
        }];
    }
}

- (void)configLocationManager
{
    self.locationManager = [[AMapLocationManager alloc] init];
    
    [self.locationManager setDelegate:self];
    
    //设置期望定位精度
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    
    //设置定位超时时间
    [self.locationManager setLocationTimeout:DefaultLocationTimeout];
    
    //设置逆地理超时时间
    [self.locationManager setReGeocodeTimeout:DefaultReGeocodeTimeout];
    
    //设置允许连续定位逆地理
    [self.locationManager setLocatingWithReGeocode:YES];
    
    [self.locationManager startUpdatingLocation];
}

- (void)cleanUpAction
{
    //停止定位
    [self.locationManager stopUpdatingLocation];
    
    [self.locationManager setDelegate:nil];
    
}

#pragma mark - AMapLocationManager Delegate

/**
 *  @brief 连续定位回调函数.注意：如果实现了本方法，则定位信息不会通过amapLocationManager:didUpdateLocation:方法回调。
 *  @param manager 定位 AMapLocationManager 类。
 *  @param location 定位结果。
 *  @param reGeocode 逆地理信息。
 */
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode
{
    NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
    
    _longitude = CJStringWithFormat(@"%f",location.coordinate.longitude);
    _latitude = CJStringWithFormat(@"%f",location.coordinate.latitude);
    
    [UserDefaultUtil saveValue:CJStringWithFormat(@"%f",location.coordinate.longitude) forKey:LONGITUDE];
    [UserDefaultUtil saveValue:CJStringWithFormat(@"%f",location.coordinate.latitude) forKey:LATITUDE];
    
    //详细信息
    if (reGeocode)
    {
        NSLog(@"reGeocode:%@", reGeocode);
        _locateAddress = reGeocode.formattedAddress;
    }
    
}

- (void)amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager *)locationManager
{
    [locationManager requestAlwaysAuthorization];
}

/**
 *  @brief 当定位发生错误时，会调用代理的此方法。
 *  @param manager 定位 AMapLocationManager 类。
 *  @param error 返回的错误，参考 CLError 。
 */
- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error {
    
    DebugLog(@"定位error：%@",error);
}
- (void)dealloc
{
    [KNotificationCenter removeObserver:self name:@"faceIdentifySuccess" object:nil];
    [self cleanUpAction];
}

#pragma mark - 定位权限是否是始终
- (BOOL)locationIsAlwaysAuth {
    
    if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways)) {
        //非始终定位权限
        UIAlertController *alertView=[UIAlertController alertControllerWithTitle:@"⚠️警告⚠️" message: CJStringWithFormat(@"请到设置->隐私->定位服务->【%@】切换到始终，否则将影响到您的轨迹上报", APP_NAME) preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"立即前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
        }];
        UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertView addAction:sureAction];
        [alertView addAction:cancelAction];
        
        [self presentViewController:alertView animated:YES completion:nil];
        
        return NO;
        
    } else {
        
        return YES;
    }
    
    return NO;
}

- (NSMutableArray *)imageArr {
    if (!_imageArr) {
        _imageArr = [[NSMutableArray alloc] initWithObjects:image(@"gcy_btn_add_photo"), image(@"gcy_btn_add_photo"), image(@"gcy_btn_add_photo"), nil];
    }
    return _imageArr;
}
- (NSMutableArray *)imageUrlArray {
    if (!_imageUrlArray) {
        _imageUrlArray = [[NSMutableArray alloc] init];
    }
    return _imageUrlArray;
}
@end
